# frozen_string_literal: true

FactoryBot.define do
  sequence(:rule_seq_name) { |n| "rule name #{n}" }
  sequence(:rule_seq_description) { |n| "rule description #{n}" }

  factory :rule, aliases: [:rule_general_rule] do
    name { generate :rule_seq_name }
    current_version { nil }
    type { Rule::GeneralRule }
    status { Rule::Status::CREATED }
    description { generate :rule_seq_description }

    trait :general_rule do
      type { Rule::GeneralRule }
    end

    trait :rule_set do
      type { Rule::RuleSet }
    end

    trait :decision_table do
      type { Rule::DecisionTable }
    end

    trait :created do
      status { Rule::Status::CREATED }
    end

    trait :deployed do
      status { Rule::Status::CREATED }

      after(:create) do |rule|
        rule_version = create(:rule_version, rule: rule)
        rule.update current_version: rule_version.version
      end
    end

    trait :deprecated do
      status { Rule::Status::CREATED }
    end

    trait :deleted do
      status { Rule::Status::CREATED }
    end
  end
end
